package com.qianfeng.service.impl;

import com.qianfeng.exception.AddDataException;
import com.qianfeng.mapper.HumitureMapper;
import com.qianfeng.pojo.SysHumiture;
import com.qianfeng.service.HumitureService;
import com.qianfeng.status.ResultCode;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.Date;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/9/14 21:17
 */
@Service
@Transactional
public class HumitureServiceImpl implements HumitureService {
    private HumitureMapper humitureMapper;

    public void setHumitureMapper(HumitureMapper humitureMapper) {
        this.humitureMapper = humitureMapper;
    }

    @Override
    @EventListener
    public void addHumiture(SysHumiture humiture) {
        Assert.isTrue(humiture!=null,()->{
            throw new AddDataException("未获取到数据", ResultCode.PARAM_CONTENT_EMPTY);
        });
        humiture.setUploadTime(new Date());
        humitureMapper.addHumiture(humiture);

    }
}
